package com.ful.servlet;

import com.ful.domain.Product;
import com.ful.domain.Users;
import com.ful.service.ProductService;
import com.ful.service.UsersService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class FindProductAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 1.获得请求参数（可无）
         * 2.调用业务逻辑
         * 3.获得结果
         * 4.根据结果判断是否需要共享数据（request/session/application）[类比保存一天、一个月、一年]
         * 5。转发或重定向
         */
        ProductService ps = new ProductService();
        List<Product> data =  ps.findByAll();
        //session共享
        HttpSession session = request.getSession();
        //共享
        session.setAttribute("productdata",data);
        response.sendRedirect("products.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
